package com.example.work3_1;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioButton;

public class MainActivity extends Activity {
	RadioButton r1 = null;
	RadioButton r2 = null;
	RadioButton r3 = null;
	RadioButton r4 = null;
	RadioGroup radioGroup = null;
	RadioButton currentRadioButton=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        radioGroup = (RadioGroup) findViewById(R.id.rg1);
        r1 = (RadioButton) findViewById(R.id.a);
        r2 = (RadioButton) findViewById(R.id.b);
        r3 = (RadioButton) findViewById(R.id.c);
        r4 = (RadioButton) findViewById(R.id.d);
        r1.setClickable(true);
        radioGroup.setOnCheckedChangeListener(mChangeRadio);
        Button btn1_sure =(Button)findViewById(R.id.sure);
        Button btn2_cancal =(Button)findViewById(R.id.cancal);
        btn1_sure.setOnClickListener(new btn1_sure());
        btn2_cancal.setOnClickListener(new btn2_cancal());
    }
    class btn1_sure implements OnClickListener{
    	public void onClick(View v){
    		if(currentRadioButton.getText().equals("in")){
    			setTitle("Your select this answer is correct!");
    		}
    		else{
    			setTitle("Your select this answer is wrong!");
    		}
    	}
    }
    class btn2_cancal implements OnClickListener{
    	public void onClick(View v){
    		radioGroup.clearCheck();
    		setTitle("");
    	}
    }
    private RadioGroup.OnCheckedChangeListener mChangeRadio = new RadioGroup.OnCheckedChangeListener() {
		
		@Override
		public void onCheckedChanged(RadioGroup arg0, int checkedId) {
			// TODO Auto-generated method stub
			if(checkedId == r1.getId()){
				currentRadioButton=r1;
			} else if(checkedId == r2.getId()){
				currentRadioButton=r2;
			}else if(checkedId == r3.getId()){
				currentRadioButton=r3;
			}else if(checkedId == r4.getId()){
				currentRadioButton=r4;
			}
		}
	};
}
